package com.surekam.dma.service.dma.list;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.orm.Page;
import org.springside.modules.orm.PropertyFilter;
import org.springside.modules.security.springsecurity.SpringSecurityUtils;

import com.surekam.dma.dao.dma.list.DirectoryDao;
import com.surekam.dma.entity.dma.list.Directory;


@Component
//默认将类中的所有函数纳入事务管理.
@Transactional
public class DirectoryManager {
	private static Logger logger = LoggerFactory.getLogger(DirectoryManager.class);

	private DirectoryDao directoryDao;

	/**
	 * 使用属性过滤条件查询用户.
	 */
	@Transactional(readOnly = true)
	public Page<Directory> searchDirectory(final Page<Directory> page, final List<PropertyFilter> filters) {
		return directoryDao.findPage(page, filters);
	}

	@Transactional(readOnly = true)
	public Directory findDirectoryByName(String name){
		return directoryDao.findUniqueBy("name", name);
	}

	public Directory getDirectory(Long id){
		return directoryDao.get(id);
	}
	
	public void saveDirectory(Directory entity) {
		directoryDao.save(entity);
	}

	public void deleteDirectory(Long id) {
		logger.warn("删除主题 " + id, SpringSecurityUtils.getCurrentUserName());
		directoryDao.delete(id);
	}

	//-- Authority Manager --//
	@Transactional(readOnly = true)
	public List<Directory> getAllDirectory() {
		return directoryDao.getAll();
	}

	@Autowired
	public void setDirectoryDao(DirectoryDao directoryDao){
		this.directoryDao = directoryDao;
	}
	
}